#pragma once
#include  "HuffmanTreeNode.h"
#include <stdint.h>
#include <queue>

class FrequencyTable;
class IHTreeCallBack;

typedef void (*CallBack)(HuffmanTreeNode* node);

class HTree
{
public:
	HTree(FrequencyTable* table);
	~HTree(void);
	// only use right bits
	uint32_t getCode(uint8_t byte, size_t& bits);
	void archiveByte(uint8_t byte);
	void unArchivebyte(uint8_t byte);
	IHTreeCallBack* myDelegate;
private:
	HuffmanTreeNode* root;
	// state of the finite state machine
	HuffmanTreeNode* state;
	FrequencyTable* table;
	// mb better take out to tree builder?
	std::priority_queue<HuffmanTreeNode> queue;
	void dfs(HuffmanTreeNode* ver, CallBack helper);
	static void nodeDeleter(HuffmanTreeNode* node);
};

